package com.openess.bigsearch.engine.utils.sort;

import java.util.Comparator;

/**
 * 冒泡排序法，实现简单
 * 
 * @author TuTu
 * 
 * @param <E>
 */
public class BubbleSort<E> implements Sort<E> {
	public void sort(E[] array, int p, int r, Comparator<? super E> c) {
		boolean exchange = true;
		int n = -1;
		for (int i = p + 1; i <= r && exchange; i++) {
			exchange = false;
			n++;
			for (int j = p; j < r - n; j++) {
				if (c.compare(array[j], array[j + 1]) > 0) {
					E temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
					exchange = true;
				}
			}
		}
	}
}
